package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApAuthorMapper;
import com.heima.article.service.ApAuthorService;
import com.heima.common.exception.CustomException;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApAuthorMapper;
import com.heima.article.service.ApAuthorService;
import com.heima.model.common.pojos.article.ApAuthor;
import org.springframework.stereotype.Service;

@Service
public class ApAuthorServiceImpl extends ServiceImpl<ApAuthorMapper, ApAuthor> implements ApAuthorService {
    /**
     * 根据作者id查询用户信息
     *
     * @param authorId
     * @return
     */
    @Override
    public ResponseResult getUserInfo(Integer authorId) {
        if (authorId < 0) {
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        ApAuthor apAuthor = getOne(Wrappers.lambdaQuery(ApAuthor.class).eq(ApAuthor::getWmUserId, authorId));
        if (apAuthor == null) {
            throw new CustomException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return ResponseResult.okResult(apAuthor);
    }
}
